<template>
  <div>
    <ReviewEdit @parent="reload" :show.sync="myshow" :editId="editId" :clickNum="clickNum"></ReviewEdit>
    <tableComponents :pagination="{ currentPage, pageSize, total: list.all_num }" @handleCurrentChange="handleCurrentChange"
        @handleSizeChange="handleSizeChange" @sendUserSearch="getSearch" :searchData="userSearchData" :isHaveExport="false"
        @toAdd="showEditDialog('0')">
      <template v-slot:table>
        <el-table ref="multipleTable" :data="list.data" v-loading="loading" stripe header-row-class-name="head_color" tooltip-effect="dark"
            style="width: 99.9%" @selection-change="handleSelectionChange">
          <el-table-column type="selection" class="tc" width="35"></el-table-column>

          <el-table-column label="评价类型" min-width="50">
            <template slot-scope="scope">{{
              scope.row.types == 2
                ? "酒店"
                : scope.row.types == 1
                ? "商品"
                : "随手拍"
            }}</template>
          </el-table-column>

          <el-table-column label="图片" min-width="50" align="center">
            <template slot-scope="scope">
              <div class="img_bor">
                <img :src="$fnc.getImgUrl(scope.row.pid_pic)" alt />
              </div>
            </template>
          </el-table-column>

          <el-table-column label="标题" min-width="80">
            <template slot-scope="scope">
              <div class="tab_div">
                <div>{{ scope.row.pid_cn }}</div>
                <div>
                  <span>评分：</span>
                  <el-rate style="display:inline-block;" :value="parseInt(scope.row.star)" disabled disabled-void-icon-class="out_rete"
                      text-color="#ff9900"></el-rate>
                </div>
              </div>
            </template>
          </el-table-column>

          <el-table-column label="头像" min-width="50">
            <template slot-scope="scope">
              <div class="img_bor_tx">
                <img :src="$fnc.getImgUrl(scope.row.avatar)" alt />
              </div>
            </template>
          </el-table-column>

          <el-table-column label="用户信息" min-width="100">
            <template slot-scope="scope">
              <div class="tab_div">
                <div>
                  <span>用户昵称：</span>
                  <span>{{ scope.row.uid_cn }}</span>
                </div>
                <div>
                  <span>会员账号：</span>
                  <span>{{ scope.row.uid }}</span>
                </div>
                <div>
                  <span>用户等级：</span>
                  <span class="rat" v-show="scope.row.rating_cn">{{
                    scope.row.rating_cn
                  }}</span>
                </div>
                <div>
                  <span>被举报次数：</span>
                  <span>{{ scope.row.report_num }}</span>
                </div>
              </div>
            </template>
          </el-table-column>

          <el-table-column label="内容" min-width="180">
            <template slot-scope="scope">
              <div class="tab_div">
                <div>
                  <span>评价内容：</span>
                  <span>{{ scope.row.content }}</span>
                </div>
                <!-- <div>
                  <span>评价时间：</span>
                  <span>{{ scope.row.update_time | getTimeFormat }}</span>
                </div> -->
                <div v-if="scope.row.reply && scope.row.reply != ''">
                  <span>回复内容：</span>
                  <span>{{ scope.row.reply }}</span>
                </div>
              </div>
            </template>
          </el-table-column>

          <el-table-column label="是否审核" min-width="100">
            <template slot-scope="scope">
              <el-switch class="zdySwith" :width="82" v-model="scope.row.is_check" active-color="#1aad19" inactive-color="#ffffff" active-text="审核"
                  inactive-text="未审核" active-value="1" @change="getIskeck($event, scope.row)" inactive-value="0"></el-switch>
            </template>
          </el-table-column>

          <el-table-column label="操作" align="center" min-width="100">
            <template slot-scope="scope">
              <el-button :loading="$store.state.isLoading" type="primary" size="mini" @click="showEditDialog(scope.row.id)">查看</el-button>
              <el-button :loading="$store.state.isLoading" @click="uploadVideo(scope.row.id, scope.row.video)" size="mini"
              v-if="$store.state.plugin && $store.state.plugin.yspdb && $store.state.plugin.yspdb.is_open == 1"
              >短视频</el-button>
              <el-button :loading="$store.state.isLoading" size="mini" @click="deleteNew(scope.$index, scope.row.id)" type="danger">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
      </template>
      <template v-slot:footerLeft>
        <a class="aBtn aBtn_1 aBtn_lan2" @click="delSelection">删除</a>
      </template>
    </tableComponents>

    <el-dialog :close-on-click-modal="false" title="上传视频" :append-to-body="true" :visible.sync="dialogvideoVisible">
      <uploadvideo @send_url="rev_send_url" :pro_src="formVideo.video"></uploadvideo>
    </el-dialog>
  </div>
</template>
<script>
import ReviewEdit from "@/components/shop/review_edit.vue";
import { shopReviewSearchData } from "@/assets/js/searchData/searchData"; //引入搜索的数据
import uploadvideo from "@/components/currency/uploadvideo";
export default {
  data () {
    return {
      userSearchData: shopReviewSearchData,
      formVideo: {
        video: ""
      },
      dialogvideoVisible: false,
      show: false,
      myshow: false,
      loading: false,
      list: [],
      allPage: 0,
      allNum: 0,
      pageSize: 10,
      currentPage: 1,
      editId: "",
      multipleSelection: "",
      arr: [],
      visible: false,
      clickNum: 1,
      updataIndex: "",
      searchAll: {}
    };
  },
  components: {
    ReviewEdit,
    uploadvideo
  },
  methods: {
    rev_send_url (val) {
      console.log(val);
      var params = {};
      console.log(val);
      this.formVideo.video = val.video_url || "";
      this.formVideo.video_piclink = val.video_pic || "";
      this.formVideo.vid = val.video_id || "";
      params = this.formVideo;

      this.$api.getShops.reviewSaveEdit(params).then(res => {
        if (res.data.code == 200) {
          this.$fnc.alertSuccess({ text: "提交成功" });
          this.dialogvideoVisible = false;
          this.formVideo.id = "";
          this.formVideo.video = "";
          this.formVideo.video_pic = "";
          this.getNewsAll(this.searchAll);
        } else {
          this.$fnc.alertError(res.data.code_desc, res.data.result);
        }
      });
    },
    uploadVideo (id, video) {
      this.dialogvideoVisible = true;
      this.formVideo.id = id;
      this.formVideo.video = video || "";
    },

    getIskeck (val, row) {
      var params = {};
      params.id = row.id;
      params.is_check = val;
      this.$api.getShops.reviewSaveEdit(params).then(res => {
        if (res.data.code == 200) {
          this.$message.success("提交成功");
        } else {
          this.$fnc.alertError(res.data.result);
        }
      });
    },

    imgError (item) {
      if (!item) {
        return require("../../assets/img/default_head.png");
      }
      if (item.indexOf("http") || item.indexOf("api") >= 0) {
        return item;
      } else {
        return "/api/" + item;
      }
    },
    showAddDialog () {
      this.show = true;
    },
    getSearch (obj) {
      this.searchAll = obj;
      this.$router.push(this.$route.path + "?page=" + 1);
      this.getNewsAll(obj);
    },
    getNewsAll (data) {
      this.loading = true;
      var params = {};
      data = data || {};
      params = data;
      this.$api.getShops.getReviewList(params).then(res => {
        if (res.data.code == 200) {
          this.list = res.data.result;
        }
        this.loading = false;
      });
    },
    handleSizeChange (val) {
      var params = this.searchAll;
      params.page = "";
      params.page_size = val;
      this.getNewsAll(params);
      this.pageSize = val;
      // console.log(`每页 ${val} 条`);
    },
    handleCurrentChange (val) {
      this.$router.push(this.$route.path + "?page=" + val);
    },
    handleSwitch (val, id) {
      //审核
      var params = {};
      params["id"] = id;
      val == true ? (params["is_check"] = 1) : (params["is_check"] = 0);
      this.$api.getUser.msgCheck(params).then(res => {
        // this.getNewsAll();
        if (res.data.code == 400) {
          this.$fnc.alertError(res.data.code_desc, res.data.result);
        }
      });
    },
    handleSelectionChange (val) {
      //多选框赋值
      this.multipleSelection = val;
    },
    delSelection () {
      //删除
      this.$swal({
        title: "您确定要删除这条信息吗",
        text: "删除后将无法恢复，请谨慎操作！",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "是的，我要删除",
        cancelButtonText: "容我三思"
      }).then(willDelete => {
        if (willDelete.value) {
          var str = "";
          for (var i in this.multipleSelection) {
            str += this.multipleSelection[i].id + "@";
          }
          str = str.slice(0, -1);

          var data = { id_str: str };
          this.$api.getShops.reviewDel(data).then(res => {
            if (res.data.code) {
              this.getNewsAll(this.searchAll);
            }
          });
        }
      });
    },
    deleteNew (index, id) {
      this.$swal({
        title: "您确定要删除这条信息吗",
        text: "删除后将无法恢复，请谨慎操作！",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "是的，我要删除",
        cancelButtonText: "容我三思"
      }).then(willDelete => {
        if (willDelete.value) {
          var data = { id_str: id };
          this.$api.getShops.reviewDel(data).then(res => {
            if (res.data.code == 200) {
              this.$swal("删除成功！", "您已经删除了这条信息。", "success");

              this.getNewsAll();
            } else {
              this.$swal("删除失败！", "出错啦！", "success");
            }
          });
        }
      });
    },
    showEditDialog (id) {
      this.myshow = true;
      this.editId = id;
      this.clickNum++;
    },
    reload (id) {
      this.getNewsAll(this.searchAll);
    }
  },

  created () {
    this.getNewsAll();
  },
  watch: {
    $route () {
      var params = this.searchAll;
      params.page = this.$route.query.page || 1;
      params.page_size = this.pageSize;
      this.getNewsAll(params);
      this.currentPage = Number(this.$route.query.page) || 1;
    }
  }
};
</script>
